package com.hk.core.authentication.security.authentication.accesstoken;

import com.hk.commons.JsonResult;
import com.hk.core.web.Webs;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

@RequiredArgsConstructor
public class AccessTokenAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
        Webs.writeJson(response, HttpServletResponse.SC_OK, JsonResult.unauthorized(exception.getMessage()));
    }
}
